from django.shortcuts import render
from django.core import serializers
from django.http import JsonResponse

from .models import Personnel


def get_personnel(request):
    personnels = Personnel.objects.all()
    response_data = {}

    try:
        response_data['result'] = 'Success'
        response_data['message'] = serializers.serialize('json', personnels)
    except:
        response_data['result'] = 'Ouch'
        response_data['message'] = 'Script has not ran correctly'

    return JsonResponse(response_data)
